namespace('is', new function() {
    var def = 'def'

    this.cache = {
        init: {},
        reapply: {},
        onopen_east: {},
        onopen_west: {},
        onopen_main: {}
    }

    // Register a function with the object
    this.register = function(name, obj, key) {
        obj = (typeof(obj) == 'function')  ? obj : obj[name];
        key = (typeof(key) != 'undefined') ? key : def;
        if(typeof(this.cache[name]) == 'undefined') this.cache[name] = {};
        if(typeof(this.cache[name][key]) == 'undefined')
            this.cache[name][key] = new Array();
        this.cache[name][key].push(obj);
    };

    // Remove all registered actions
    this.clear = function(name, key) {
        key = (typeof(key) != 'undefined') ? key : def;
        this.cache[name] = new Array();
    }

    // Return all the keys for a registered method
    this.keys = function(name) {
        var a = new Array();
        for(var i in this.cache[name]) a.push(i);
        return a;
    }

    // Automatically bind all functions to this object
    this.run_method = function(name) {
        return function(key, args) {
            key  = (typeof(key)  != 'undefined') ? key : def;
            args = (typeof(args) != 'undefined') ? args : {};
            for(var i in this.cache[name][key]) this.cache[name][key][i](args);
        };
    }
    for(var i in this.cache) this[i] = this.run_method(i);

    // Automatically bind all functions to this object, with all keys
    this.run_method_all = function(name) {
        return function(args) {
            args = (typeof(args) != 'undefined') ? args : {};
            keys = is.keys(name);
            for(var i in keys) {
                for(var j in this.cache[name][keys[i]]) this.cache[name][keys[i]][j](args);
            }
        }
    }
    for(var i in this.cache) this[i + '_all'] = this.run_method_all(i);
});

$(document).ready(function(){
    is.init();
});
